<%@ page language="java" import="java.util.*,com.hs.app.model.*,com.hs.core.utils.*,com.hs.core.cache.*" pageEncoding="utf-8"%>
<%
PageUtil pageUtil = (PageUtil)request.getAttribute("dataList");
String filename = (String)request.getAttribute("filename");  
String datatype = (String)request.getAttribute("datatype");  
List dataList = null;
boolean dataStatus = false;
String pageStr = "";
int perpageCount = 0;
int currentPage = 0;
if(pageUtil != null){
	   dataList = pageUtil.getPageList();
	   pageStr = pageUtil.getPageStr();
	   perpageCount = pageUtil.getNumberPerPage();
	   currentPage = pageUtil.getCurrentPage();
 
	   if(dataList != null && !dataList.isEmpty()){
		   dataStatus = true;
}
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<%@ include file="../../../include.jsp"%>  
<script src='<%=basePath%>dwr/engine.js'></script>
<script src='<%=basePath%>dwr/util.js'></script>  
<script src='<%=basePath%>dwr/interface/impdatadwr.js'></script> 

 
<script language=JavaScript> 
function searchData(){
	searchform.submit();
}

function changeStyle(_mpid){
	alert(_mpid);
} 
 
function impDatawithDouble(fileid,datatype){
       if(confirm('确认查重导入数据吗?')){ 
             document.getElementById("impbutt1_"+fileid).disabled=true;
            document.getElementById("impbutt2_"+fileid).disabled=true;
            document.getElementById("del_" +fileid).disabled=true;
       		impdatadwr.impData(fileid,'1',datatype,callback4impDatawithDouble); 
       } 
}
function callback4impDatawithDouble(data){
  
}
function impDataNoDouble(fileid,datatype){ 
       if(confirm('确认不查重导入数据吗?')){
            document.getElementById("impbutt1_"+fileid).disabled=true;
            document.getElementById("impbutt2_"+fileid).disabled=true;
             document.getElementById("del_" +fileid).disabled=true;
       		impdatadwr.impData(fileid,'2',datatype,callback4impDatawithDouble); 
       } 
}
 
function refreshData(fileid){ 
	  impdatadwr.queryByFileId(fileid,callback4refreshData);  
}
function callback4refreshData(data){ 
	  var dataarr =  data.split('#');
      var fileidstr = dataarr[1];
      var c_num =  dataarr[0];
      var allnum =  dataarr[2];  
      var status =  dataarr[3];  
      var failnum =  dataarr[4];  
      $('#curr_'+fileidstr).html(c_num);
      if("1" == status){
            $('#status_'+fileidstr).html("<font color=red>未导入</font>");
       }else if("2"== status){
            $('#status_'+fileidstr).html("<font color=red>正在导入</font>");
       }else if("3"== status){
            $('#status_'+fileidstr).html("<font color=red>导入失败</font>");
       }else if("4"== status){
            $('#status_'+fileidstr).html("<font color=red>导入完成</font>");
       } 
       if("1" == status || "3" == status){
           document.getElementById("impbutt1_"+fileidstr).disabled=false;
           document.getElementById("impbutt2_" +fileidstr).disabled=false;
           document.getElementById("del_" +fileidstr).disabled=false;
              $('#failnum_'+fileidstr).html(failnum);
      }else{
           document.getElementById("impbutt1_"+fileidstr).disabled=true;
           document.getElementById("impbutt2_" +fileidstr).disabled=true;
       }
      if("4" == status){
           document.getElementById("refreshbutt_" +fileidstr).disabled=true; 
      }else{
           document.getElementById("refreshbutt_" +fileidstr).disabled = false; 
      }
      
}

function delFileAnddb(fileid,datatype){
    if(confirm('确认要删除该数据文件吗？数据文件时将同时删除该数据文件已导入的部分数据！')){
           impdatadwr.delByFileId(fileid,datatype,callback4deldatafile);   
    } 
}

function callback4deldatafile(data){ 
     alert("删除成功");
     searchform.submit();
}

function uploadDataFile(){
	openwindow('<%=basePath%>data/import/datafileUpload.do','800','600','');
}
</script>
 
</head>
<body>

<div class="cont"> 
<form name="searchform" action="<%=basePath %>data/import/importManage.do" method="post"> 
                <table border="0" cellpadding="0" cellspacing="0" class="tableForm">
			        <tr>
			          <th width="10%">文件名称：</th>
			          <td width="20%"><input type="text" name="filename" value="<%=filename==null?"":filename %>"  style="width:100%;" />
					</td> 
			          <th width="10%">数据类型：</th>
			          <td width="15%"><select name="datatype">
                     <option value="0" <%if("0".equals(datatype)){out.println(" selected");} %>>全部</option>
                     <option value="1" <%if("1".equals(datatype)){out.println(" selected");} %>>现代中文文献</option>
                     <option value="2" <%if("2".equals(datatype)){out.println(" selected");} %>>现代英文文献</option>
                     <option value="3" <%if("3".equals(datatype)){out.println(" selected");} %>>古籍文献</option>
                     </select>
					</td>
			        <td width="5%">
			             <input name="" type="button" class="btn btn-primary" onclick="searchData();"  value=" 查 询 "/></td>
	                     <td width="5%"> <input name="" type="button" class="btn btn-primary" onclick="uploadDataFile();"  value=" 上 传 "/> </td>
	                      
			        </tr>
			        
			      </table> 
                </form>
    
    <div class="listWrap">
       <table border="0" cellpadding="0" cellspacing="0" class="tableList">
      <tr>
         
          <th width="5%">序号</th>
            <th width="30%">文件名称</th> 
            <th width="10%">总数量</th>  
             <th width="10%">导入进度</th>  
             <th width="10%">导入状态</th>  
            <th width="10%">失败行数</th> 
           <th width="25%">操作</th>
                  
      </tr>
       <%
                     StringBuffer buffer = new StringBuffer("");
                      if(dataList != null && dataList.size()>0){   %> 
 	                	  <%  
	                	        for(int i =0;i<dataList.size();i++){
	                  		         CdcImpfileinfo  fileInfo = (CdcImpfileinfo)dataList.get(i);  
	                  		         String status = fileInfo.getImpstatus()+"";
	                  		         String failnum  = fileInfo.getImpfailpos()+"";
				        %> 
    
      <tr>
      	<td align=center>  <%=(perpageCount*(currentPage-1))+i+1 %> </td>
     
 				  	<td>  
				  			<%if(fileInfo.getFilename()!=null){
				  				 
				  				out.print(StringUtilTool.SUBTITLE(fileInfo.getFilename(), 30));
				  			} %>
				  		 
				  	</td> 
                  	<td align="center">
                    <%=fileInfo.getImpnum()==null?"":fileInfo.getImpnum()%> 
                   	</td>
                   	 <td align="center">
                    	<font color=red size=3><strong><span id="curr_<%=fileInfo.getId()%>"><%=fileInfo.getImpcurrnum()%></span></strong></font> 
                  	</td>
                    <td align="center"> <span id="status_<%=fileInfo.getId() %>">
                          <% 
                               
                                if(!"null".equals(status)){
                                    if("1".equals(status)){
                                    	out.println("<font color=red>未导入</font>");
                                    }else if("2".equals(status)){
                                        out.println("<font color=red>正在导入</font>");
                                    }else if("3".equals(status)){
                                        out.println("<font color=red>导入失败</font>");
                                    }else if("4".equals(status)){
                                        out.println("<font color=red>导入完成</font>");
                                    }
                                    
                                } 
                          %>
                          
                          </span>
                  	</td>
                  	
                   	 <td align="center">
                   	    <span id="failnum_<%=fileInfo.getId() %>">
                   	    <%if("0".equals(failnum)) { 
                   	        out.println("无");     
                   	    }else{%>
                   	  	 <%=fileInfo.getImpfailpos()%>
                   	  	 <%} %>  
                   	  	 </span>
                     </td>  
                  	<td align="center"> 
                  	     <%
                  	    String isrefresh = "";
                  	     if("4".equals(status)){   
                  	           isrefresh =  "disabled";
                  	     } %>
                    	 <input type="button" value=" 刷新 " class="btn btn-primary" id="refreshbutt_<%=fileInfo.getId() %>" onclick="refreshData('<%=fileInfo.getId() %>')";  <%=isrefresh %>/>
                  	     <%  String isdisable = "disabled";
                  	       if("1".equals(status)||"3".equals(status)){
                  	              isdisable = "";
                  	       } %>
                    	 		<input type="button" class="btn btn-primary" value="导入并查重" id="impbutt1_<%=fileInfo.getId() %>"   onclick="impDatawithDouble('<%=fileInfo.getId() %>','<%=fileInfo.getDatatype() %>')";    <%=isdisable %>/> 
                    	 		<input type="button" class="btn btn-primary" value="导入不查重" id="impbutt2_<%=fileInfo.getId() %>"   onclick="impDataNoDouble('<%=fileInfo.getId() %>','<%=fileInfo.getDatatype() %>');"    <%=isdisable %>/>
                    	 		 
                    	 <input type="button" class="btn btn-primary"  value="删除" id="del_<%=fileInfo.getId() %>"   onclick="delFileAnddb('<%=fileInfo.getId() %>','<%=fileInfo.getDatatype() %>');"   <%=isdisable %>/>
                  	</td> 
				  </tr>
				  <%  } %>
                	<%} %><%else{ %>
				<tr>
            		<td colspan=7 align="center">
            			<font color=red><strong>当前没有上传的数据文件，请先上传！</strong></font>
            		</td>
          		</tr>
          <%} %> 
    </table> 
    
    <div class="pageWrap">
        <div class="result"></div>
        <div class="page">
              <%=pageStr %>
        </div>
    </div>
    </div>
</div> 
</body>
</html>